package com.jingsheng.jingshengcity.mvp.ui.activity.wallet;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerTransactionRecordsComponent;
import com.jingsheng.jingshengcity.di.module.TransactionRecordsModule;
import com.jingsheng.jingshengcity.mvp.contract.TransactionRecordsContract;
import com.jingsheng.jingshengcity.mvp.model.entity.TransactionRecordsEntity;
import com.jingsheng.jingshengcity.mvp.presenter.TransactionRecordsPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.TransactionRecordsActivityAdapter;
import com.jingsheng.jingshengcity.widgets.decoration.GridItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/12.
 */

public class TransactionRecordsActivity extends BaseActivity<TransactionRecordsPresenter> implements TransactionRecordsContract.View, SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener {

    @NonNull
    @BindView(R.id.swipe_layout)
    SwipeRefreshLayout mSwipeRefreshLayout;
    @NonNull
    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;

    private List<TransactionRecordsEntity> mList = new ArrayList<>();

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerTransactionRecordsComponent
                .builder()
                .appComponent(appComponent)
                .transactionRecordsModule(new TransactionRecordsModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("交易记录");
        return R.layout.activity_transaction_records;
    }

    @Override
    public void initData() {
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mList.add(new TransactionRecordsEntity(TransactionRecordsEntity.DATE));
        mList.add(new TransactionRecordsEntity(TransactionRecordsEntity.ITEM));
        mList.add(new TransactionRecordsEntity(TransactionRecordsEntity.ITEM));

        TransactionRecordsActivityAdapter mHomePageFragmentAdapter = new TransactionRecordsActivityAdapter(mList);
        mHomePageFragmentAdapter.openLoadAnimation();
        mRecyclerView.addItemDecoration(new GridItemDecoration(this, R.drawable.list_gray_devider));
        mRecyclerView.setAdapter(mHomePageFragmentAdapter);
        mHomePageFragmentAdapter.setOnLoadMoreListener(this, mRecyclerView);

        mHomePageFragmentAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.rl_item:
                        Intent intent = new Intent(TransactionRecordsActivity.this, RecordDetailActivity.class);
                        startActivity(intent);
                        break;
                }
            }
        });
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public boolean useFragment() {
        return false;
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMoreRequested() {

    }
}